function y = minDistSearch(pt,model,model_para)

        min_d = inf;
        nbThr = 10;
        
        X = pt(1);
        Y = pt(2);
        
%         cnt_nb1 = 0;
        
        for i=1:size(model,3),
                                    
            minx_nb = min(model(1,:,i));            
            maxx_nb = max(model(1,:,i));
            
            a = model_para(1,i);
            b = model_para(2,i);
            eps = model_para(3,i);
            
            if isinf(a)  % case segment is part of a straight line
                
                miny_nb = min(model(2,:,i));
                maxy_nb = max(model(2,:,i));
                
                if (X>=minx_nb-nbThr)&&(X<=maxx_nb+nbThr)&& ...
                        (Y>=miny_nb-nbThr)&&(Y<=maxy_nb+nbThr),

                    dist = abs(X-minx_nb);
                    if dist < min_d, min_d = dist; end
%                 else 
%                     cnt_nb1 = cnt_nb1 + 1;
                end
                
            else
                
                y_l = a*X + b;  % y_l = a*x + b                
                
                if (X>=minx_nb-nbThr)&&(X<=maxx_nb+nbThr)&& ...
                        (Y>=y_l-eps)&&(Y<=y_l+eps),
                    
                    dist = DistP2Segment(pt,model(:,:,i),[a b]');
                    if dist < min_d, min_d = dist; end
                    %             else
                    %                 min_d = inf;
                    %                 break;
%                 else
%                     cnt_nb1 = cnt_nb1 + 1;
                end
            end
            
        end
                
%         cnt_nb1
        
        y = min_d;
end